home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWToolbx / Sources / SLWindow.cpp < prev   
Encoding:
Text File  |  1996-08-16  |  23.7 KB  |  866 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLWindow.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLWINDOW_H
  13. #include "SLWindow.h"
  14. #endif
  15.  
  16. #ifndef FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #ifndef FWMEMORY_H
  21. #include "FWMemory.h"
  22. #endif
  23.  
  24. #ifndef FWRESOUR_H
  25. #include "FWResour.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWFCTINF_H
  33. #include "FWFctInf.h"
  34. #endif
  35.  
  36. #ifndef FWACQUIR_H
  37. #include "FWAcquir.h"
  38. #endif
  39.  
  40. #ifndef FWSTRING_H
  41. #include "FWString.h"
  42. #endif
  43.  
  44. #ifndef SLMIXOS_H
  45. #include "SLMixOS.h"
  46. #endif
  47.  
  48. #if defined(FW_BUILD_MAC) && !defined(FWMACOS_H)
  49. #include "SLMacOS.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Includes -----
  53.  
  54. #ifndef _ITEXT_
  55. #include "IText.h"
  56. #endif
  57.  
  58. #ifndef SOM_ODWindow_xh
  59. #include <Window.xh>
  60. #endif
  61.  
  62. #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
  63. #include <Resources.h>
  64. #endif
  65.  
  66. //========================================================================================
  67. //    Runtime Info
  68. //========================================================================================
  69.  
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment fwtoolbx
  72. #endif
  73.  
  74. //========================================================================================
  75. //    defines
  76. //========================================================================================
  77.  
  78. #ifdef FW_BUILD_MAC
  79. #define FW_kSystem75WindoidWDEF        1985            //     System 7.5 windoid 
  80. #define FW_kNonSystem75WindoidWDEF    48                //     System 7.5 windoid (for system < 7.5)
  81. #define FW_kSystem75ToggleTBar        1                //    Bit 0 tell us whether to hilite/unhilite the tittle bar
  82. #define FW_kSystem75HasGrow            2                //    Bit 1 is the grow bit
  83. #define FW_kSystem75HasZoom            4                //    Bit 2 is the zoom bit
  84. #define FW_kSystem75VertTBar        8                //    bit 3 is for a vertical tittle bar
  85. #endif
  86.  
  87. //========================================================================================
  88. //    Global Members
  89. //========================================================================================
  90.  
  91. #ifdef FW_BUILD_MAC
  92. Handle FW_gMacFloatWindowProc = NULL;
  93. #endif
  94.  
  95. //========================================================================================
  96. // Window Utilities
  97. //========================================================================================
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // FW_PrivFitRect
  101. //----------------------------------------------------------------------------------------
  102. //    return:
  103. //        0: nothing changed
  104. //        1: position changed
  105. //        2: size changed
  106. //        3: position and size changed
  107.  
  108. static short FW_PrivFitRect(const FW_CRect& containingRect, FW_CRect& rect)
  109. {
  110.     // This static function needs no try block - Do not throw!
  111.     short changed = 0;
  112.     
  113.     // ----- Be sure that it fits on the screen -----
  114.     if (rect.left < containingRect.left)
  115.     {
  116.         changed |= 0x0001;
  117.         rect.Offset(containingRect.left - rect.left, FW_kFixed0);
  118.     }
  119.  
  120.     if (rect.top < containingRect.top)
  121.     {
  122.         changed |= 0x0001;
  123.         rect.Offset(FW_kFixed0, containingRect.top - rect.top);
  124.     }
  125.  
  126.     if (rect.right > containingRect.right)
  127.     {
  128.         changed |= 0x0001;
  129.         rect.Offset(containingRect.right - rect.right, FW_kFixed0);
  130.         if (rect.left < containingRect.left)
  131.         {
  132.             changed |= 0x0002;
  133.             rect.left = containingRect.left;
  134.         }
  135.     }
  136.     
  137.     if (rect.bottom > containingRect.bottom)
  138.     {
  139.         changed |= 0x0001;
  140.         rect.Offset(FW_kFixed0, containingRect.bottom - rect.bottom);
  141.         if (rect.top < containingRect.top)
  142.         {
  143.             changed |= 0x0002;
  144.             rect.top = containingRect.top;
  145.         }
  146.     }
  147.     
  148.     return changed;
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_SetWindowSize
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void SL_API FW_SetWindowSize(ODPlatformWindow platformWindow, const FW_SPoint& interiorSize, FW_PlatformError* error)
  156. {    
  157.     // No try block necessary - Do not throw
  158.     *error = FW_xNoError;
  159.  
  160. #ifdef FW_BUILD_MAC
  161.     ::SizeWindow(platformWindow, FW_FixedToInt(interiorSize.x), FW_FixedToInt(interiorSize.y), TRUE);
  162. #endif
  163.  
  164. #ifdef FW_BUILD_WIN
  165.     FW_CRect borderSize;
  166.     FW_GetWindowBorderSize(platformWindow, borderSize, error);
  167.     if (*error)
  168.         return;
  169.     
  170.     FW_CPlatformRect windowRect;
  171.     ::GetWindowRect(platformWindow, &windowRect);
  172.  
  173.     int width  = FW_FixedToInt(interiorSize.x + borderSize.left + borderSize.right);
  174.     int height = FW_FixedToInt(interiorSize.y + borderSize.top + borderSize.bottom);
  175.  
  176.     ::MoveWindow(platformWindow, //::GetParent(platformWindow), 
  177.                 windowRect.left, windowRect.top, 
  178.                 width, height,
  179.                 TRUE);
  180. #endif
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_SetWindowPosition
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void SL_API FW_SetWindowPosition(ODPlatformWindow platformWindow, const FW_SPoint& newPosition, FW_PlatformError* error) 
  188. {
  189.     // No try block necessary - Do not throw
  190.     *error = FW_xNoError;
  191.  
  192. #ifdef FW_BUILD_MAC
  193.     FW_CRect borderSize;
  194.     FW_GetWindowBorderSize(platformWindow, borderSize, error);
  195.     if (*error)
  196.         return;
  197.     
  198.     ::MoveWindow(platformWindow, FW_FixedToInt(newPosition.x + borderSize.left), FW_FixedToInt(newPosition.y + borderSize.top), FALSE);
  199. #endif
  200.  
  201. #ifdef FW_BUILD_WIN
  202.     FW_CPlatformRect windowRect;
  203.     ::GetWindowRect(platformWindow, &windowRect);
  204.     
  205.     ::MoveWindow(platformWindow,        //::GetParent(platformWindow), 
  206.                 FW_FixedToInt(newPosition.x), FW_FixedToInt(newPosition.y), 
  207.                 windowRect.right - windowRect.left,
  208.                 windowRect.bottom - windowRect.top,
  209.                 FALSE);
  210. #endif
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // FW_PositionModalDialog
  215. //----------------------------------------------------------------------------------------
  216.  
  217. void SL_API FW_PositionModalDialog(ODPlatformWindow platformWindow, FW_PlatformError* error)
  218. {
  219.     // No try block necessary - Do not throw
  220.     *error = FW_xNoError;
  221.  
  222. #ifdef FW_BUILD_MAC
  223.     FW_CPoint exteriorSize;
  224.     exteriorSize.x = FW_IntToFixed(platformWindow->portRect.right - platformWindow->portRect.left);
  225.     exteriorSize.y = FW_IntToFixed(platformWindow->portRect.bottom - platformWindow->portRect.top);
  226.     
  227.     FW_CRect borderSize;
  228.     FW_GetWindowBorderSize(platformWindow, borderSize, error);
  229.     if (*error)
  230.         return;
  231.  
  232.     exteriorSize.x += borderSize.left + borderSize.right;
  233.     exteriorSize.y += borderSize.top + borderSize.bottom;    
  234.     
  235.     FW_CRect dialogRect(FW_kFixed0, FW_kFixed0, exteriorSize.x, exteriorSize.y);
  236. #endif
  237.  
  238. #ifdef FW_BUILD_WIN
  239.     FW_CPlatformRect windowRect;
  240.     ::GetWindowRect(platformWindow, &windowRect);
  241.     FW_CRect dialogRect(windowRect);
  242. #endif    
  243.  
  244.     FW_CenterRectOnScreen(dialogRect, TRUE, TRUE, TRUE);
  245.  
  246.     FW_SetWindowPosition(platformWindow, dialogRect.TopLeft(), error);
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // FW_FitWindowToScreen
  251. //----------------------------------------------------------------------------------------
  252.  
  253. FW_Boolean SL_API FW_FitWindowToScreen(ODPlatformWindow platformWindow, FW_PlatformError* error)
  254. {
  255.     // No try block necessary - Do not throw
  256.     *error = FW_xNoError;
  257.  
  258.     FW_CRect border;
  259.     FW_GetWindowBorderSize(platformWindow, border, error);
  260.     if (*error)
  261.         return false;
  262.  
  263. #ifdef FW_BUILD_MAC
  264.     FW_CRect screenRect;
  265.     ::FW_MacGetMaxIntersectedDevice(platformWindow, screenRect, error);
  266.     if (*error)
  267.         return false;
  268.     screenRect.Inset(FW_IntToFixed(3), FW_IntToFixed(3));    // leave space around window structure area
  269. #endif
  270.  
  271. #ifdef FW_BUILD_WIN
  272.     FW_CPlatformRect plScreenRect;
  273.     ::GetWindowRect(::GetDesktopWindow(), &plScreenRect);
  274.     FW_CRect screenRect(plScreenRect);
  275. #endif
  276.  
  277. #ifdef FW_BUILD_MAC
  278.     FW_CPoint windowPos, windowSize;
  279.     
  280.     FW_GetWindowPosition(platformWindow, windowPos, error);
  281.     if (*error)
  282.         return false;
  283.  
  284.     FW_GetWindowSize(platformWindow, windowSize, error);
  285.     if (*error)
  286.         return false;
  287.  
  288.     FW_CRect windowRect(windowPos.x,
  289.                         windowPos.y,
  290.                         windowPos.x + windowSize.x + border.left + border.right,
  291.                         windowPos.y + windowSize.y + border.top + border.bottom);
  292. #endif
  293.  
  294. #ifdef FW_BUILD_WIN
  295.     FW_CPlatformRect plWindowRect;
  296.     ::GetWindowRect(platformWindow, &plWindowRect);
  297.     FW_CRect windowRect(plWindowRect);
  298. #endif
  299.     
  300.     short changed = FW_PrivFitRect(screenRect, windowRect);
  301.         
  302.     if ((changed & 0x0001) != 0)
  303.     {
  304.         FW_SetWindowPosition(platformWindow, windowRect.TopLeft(), error);
  305.         if (*error)
  306.             return false;
  307.     }
  308.     
  309.     if ((changed & 0x0002) != 0)
  310.     {
  311.         FW_CPoint windowSize(windowRect.Width() - border.left - border.right, 
  312.                              windowRect.Height() - border.top - border.bottom);
  313.         FW_SetWindowSize(platformWindow, windowSize, error);
  314.     }
  315.     
  316.     return (changed != 0);
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. //    FW_GetWindowSize
  321. //----------------------------------------------------------------------------------------
  322.  
  323. void SL_API FW_GetWindowSize(ODPlatformWindow platformWindow, FW_SPoint& interiorSize, FW_PlatformError* error)
  324. {
  325.     // No try block necessary - Do not throw
  326.     *error = FW_xNoError;
  327.  
  328. #ifdef FW_BUILD_MAC
  329.     interiorSize.x = FW_IntToFixed(platformWindow->portRect.right - platformWindow->portRect.left);
  330.     interiorSize.y = FW_IntToFixed(platformWindow->portRect.bottom - platformWindow->portRect.top);
  331. #endif
  332.  
  333. #ifdef FW_BUILD_WIN
  334.     FW_CPlatformRect windowRect;
  335.     ::GetWindowRect(platformWindow, &windowRect);
  336.  
  337.     FW_CRect borderSize;
  338.     FW_GetWindowBorderSize(platformWindow, borderSize, error);
  339.     // if error let go
  340.     
  341.     interiorSize.x = FW_IntToFixed(windowRect.right - windowRect.left) - borderSize.left - borderSize.right;
  342.     interiorSize.y = FW_IntToFixed(windowRect.bottom - windowRect.top) - borderSize.top - borderSize.bottom;
  343. #endif    
  344. }
  345.  
  346. //----------------------------------------------------------------------------------------
  347. //    FW_GetWindowPosition
  348. //----------------------------------------------------------------------------------------
  349.  
  350. void SL_API FW_GetWindowPosition(ODPlatformWindow platformWindow, FW_SPoint& position, FW_PlatformError* error)
  351. {
  352.     // No try block necessary - Do not throw
  353.     *error = FW_xNoError;
  354.  
  355. #ifdef FW_BUILD_MAC
  356.     GrafPtr curPort;
  357.     ::GetPort(&curPort);
  358.     ::SetPort(platformWindow);
  359.     Point localToGlobal = {platformWindow->portRect.top, platformWindow->portRect.left};
  360.     ::LocalToGlobal(&localToGlobal);
  361.     ::SetPort(curPort);
  362.     
  363.     FW_CRect borderSize;
  364.     FW_GetWindowBorderSize(platformWindow, borderSize, error);
  365.     // if error let go
  366.  
  367.     position.x = FW_IntToFixed(localToGlobal.h) - borderSize.left;
  368.     position.y = FW_IntToFixed(localToGlobal.v) - borderSize.top;
  369. #endif
  370.  
  371. #ifdef FW_BUILD_WIN
  372.     FW_CPlatformRect windowRect;
  373.     ::GetWindowRect(platformWindow, &windowRect);
  374.     
  375.     position.x = FW_IntToFixed(windowRect.left);
  376.     position.y = FW_IntToFixed(windowRect.top);
  377. #endif
  378. }
  379.  
  380. //----------------------------------------------------------------------------------------
  381. // FW_GetWindowTitle
  382. //----------------------------------------------------------------------------------------
  383. //    windowTitle must have a valid buffer
  384.  
  385. void SL_API FW_GetWindowTitle(ODPlatformWindow platformWindow, FW_HString* windowTitleRep, FW_PlatformError* error)
  386. {
  387.     FW_ERR_TRY
  388.     {
  389.         FW_CString windowTitle(*windowTitleRep);
  390.     
  391.     #ifdef FW_BUILD_MAC
  392.         Str255 title;
  393.         ::GetWTitle(platformWindow, title);
  394.         windowTitle.ReplaceAll(title);
  395.     #endif
  396.     
  397.     #ifdef FW_BUILD_WIN
  398.         char title[256];
  399.         ::GetWindowText(platformWindow, title, 256);
  400.         windowTitle = title;
  401.     #endif
  402.     }
  403.     FW_ERR_CATCH
  404. }
  405.  
  406. //----------------------------------------------------------------------------------------
  407. // FW_SetWindowTitle
  408. //----------------------------------------------------------------------------------------
  409.  
  410. void SL_API FW_SetWindowTitle(ODPlatformWindow platformWindow, FW_HString windowTitleRep, FW_PlatformError* error)
  411. {
  412.     FW_ERR_TRY
  413.     {
  414.         FW_CString windowTitle(windowTitleRep);
  415.     
  416.     #ifdef FW_BUILD_MAC
  417.         Str255 title;
  418.         windowTitle.ExportPascal(title);
  419.         ::SetWTitle(platformWindow, title);
  420.     #endif
  421.     
  422.     #ifdef FW_BUILD_WIN
  423.         FW_CAcquireNulTerminatedString string(windowTitle);    
  424.         ::SetWindowText(platformWindow, string);
  425.     #endif
  426.     }
  427.     FW_ERR_CATCH
  428. }
  429.  
  430. //----------------------------------------------------------------------------------------
  431. //    FW_GetWindowBorderSize
  432. //----------------------------------------------------------------------------------------
  433. //    Returns the size of the border in pixels
  434.  
  435. void SL_API FW_GetWindowBorderSize(ODPlatformWindow platformWindow, FW_SRect &borderSize, FW_PlatformError* error)
  436. {
  437.     // No try block necessary - Do not throw
  438.     *error = FW_xNoError;
  439.  
  440.     FW_ASSERT(platformWindow != NULL);
  441.     
  442. #ifdef FW_BUILD_MAC
  443.     WindowRecord *windowRec = (WindowRecord*)platformWindow;
  444.  
  445.     FW_Boolean rgnsWereBuilt = FW_PrivMacBuildWindowRegions(platformWindow, TRUE, error);
  446.     if (*error)
  447.         return;
  448.     FW_CPlatformRect outside = (*windowRec->strucRgn)->rgnBBox;
  449.     FW_CPlatformRect inside = (*windowRec->contRgn)->rgnBBox;
  450.     FW_PrivMacBuildWindowRegions(platformWindow, rgnsWereBuilt, error);
  451.     // if error just let go
  452. #endif
  453.  
  454. #ifdef FW_BUILD_WIN
  455.     DWORD dwStyle = (DWORD)::GetWindowLong(platformWindow, GWL_STYLE);
  456.     DWORD dwExStyle = (dwStyle & DS_MODALFRAME) ? WS_EX_DLGMODALFRAME : 0L;
  457.     
  458.     FW_CPlatformRect inside;
  459.     ::GetClientRect(platformWindow, &inside);
  460.  
  461.     FW_CPlatformRect outside(inside.left, inside.top, inside.right, inside.bottom);
  462.     
  463.     ::AdjustWindowRectEx(&outside, dwStyle ^ DS_MODALFRAME, FALSE, dwExStyle);
  464. #endif
  465.  
  466.     borderSize.left = FW_IntToFixed(inside.left - outside.left);
  467.     borderSize.top = FW_IntToFixed(inside.top - outside.top);
  468.     borderSize.right = FW_IntToFixed(outside.right - inside.right);
  469.     borderSize.bottom = FW_IntToFixed(outside.bottom - inside.bottom);
  470. }
  471.  
  472. //----------------------------------------------------------------------------------------
  473. //    FW_WindowToScreen
  474. //----------------------------------------------------------------------------------------
  475.  
  476. FW_PlatformError SL_API FW_WindowToScreen(ODPlatformWindow platformWindow,
  477.                                           FW_SPoint* points, 
  478.                                           unsigned short nbPoint)
  479. {
  480.     // No try block necessary - Do not throw
  481.     FW_ASSERT(nbPoint > 1);
  482.     
  483.     FW_CPoint* casted = (FW_CPoint*)points;
  484.     
  485. #ifdef FW_BUILD_MAC
  486.     GrafPtr curPort;
  487.     ::GetPort(&curPort);
  488.     ::SetPort(platformWindow);
  489.     
  490.     FW_CPlatformPoint plfmPoint;
  491.     if (nbPoint == 1)
  492.     {
  493.         plfmPoint = *points;
  494.         ::LocalToGlobal(&plfmPoint);
  495.         *casted = plfmPoint;
  496.     }
  497.     else
  498.     {
  499.         for (unsigned short i = 0; i<nbPoint; i++)
  500.         {
  501.             plfmPoint = casted[i];
  502.             ::LocalToGlobal(&plfmPoint);
  503.             casted[i] = plfmPoint;
  504.         }
  505.     }
  506.     
  507.     ::SetPort(curPort);
  508. #endif
  509.  
  510. #ifdef FW_BUILD_WIN
  511.     FW_DEBUG_MESSAGE("Not yet implemented");
  512. #endif
  513.     
  514.     return FW_xNoError;
  515. }
  516.  
  517. //----------------------------------------------------------------------------------------
  518. //    FW_ScreenToWindow
  519. //----------------------------------------------------------------------------------------
  520.  
  521. FW_PlatformError SL_API FW_ScreenToWindow(ODPlatformWindow platformWindow,
  522.                                         FW_SPoint* points, 
  523.                                         unsigned short nbPoint)
  524. {
  525.     // No try block necessary - Do not throw    
  526.     FW_ASSERT(nbPoint > 1);
  527.  
  528.     FW_CPoint* casted = (FW_CPoint*)points;
  529.         
  530. #ifdef FW_BUILD_MAC
  531.     GrafPtr curPort;
  532.     ::GetPort(&curPort);
  533.     ::SetPort(platformWindow);
  534.     
  535.     FW_CPlatformPoint plfmPoint;
  536.     if (nbPoint == 1)
  537.     {
  538.         plfmPoint = *points;
  539.         ::GlobalToLocal(&plfmPoint);
  540.         *casted = plfmPoint;
  541.     }
  542.     else
  543.     {
  544.         for (unsigned short i = 0; i<nbPoint; i++)
  545.         {
  546.             plfmPoint = casted[i];
  547.             ::GlobalToLocal(&plfmPoint);
  548.             casted[i] = plfmPoint;
  549.         }
  550.     }
  551.     
  552.     ::SetPort(curPort);
  553. #endif
  554.  
  555. #ifdef FW_BUILD_WIN
  556.     FW_DEBUG_MESSAGE("Not yet implemented");
  557. #endif
  558.  
  559.     return FW_xNoError;
  560. }
  561.  
  562. #ifdef FW_BUILD_MAC
  563. //---------------------------------------------------------------------------------------
  564. //    FW_PrivMacCreatePlatformWindow
  565. //---------------------------------------------------------------------------------------
  566. //    position is the inside position
  567.     
  568. ODPlatformWindow FW_PrivMacCreatePlatformWindow(Environment* ev, 
  569.                                                 Str255 windowTitle,
  570.                                                 const FW_SPoint& interiorSize,
  571.                                                 const FW_SPoint& position,
  572.                                                 unsigned short procID,
  573.                                                 FW_Boolean hasCloseBox,
  574.                                                 long refCon)
  575. {
  576.     ODPlatformWindow platformWindow = NULL;
  577.  
  578.     FW_SOM_TRY
  579.     {
  580.         FW_CAcquireCFMResourceAccess qr(ev);
  581.         FW_CPlatformRect windowRect(FW_FixedToInt(position.x),  FW_FixedToInt(position.y), 
  582.                                     FW_FixedToInt(position.x) + FW_FixedToInt(interiorSize.x), 
  583.                                     FW_FixedToInt(position.y) + FW_FixedToInt(interiorSize.y));
  584.         
  585.         Handle windowProc = ::GetResource('WDEF', procID >> 4);    // Force load of the resource
  586.         platformWindow = ::NewCWindow(NULL, 
  587.                                         &windowRect, 
  588.                                         windowTitle, 
  589.                                         FALSE, 
  590.                                         procID,
  591.                                         (WindowPtr)-1L, 
  592.                                         hasCloseBox, 
  593.                                         refCon);
  594.         
  595.         // Special case with floating windows under system < 7.5
  596.         if ((procID & 0xFFF0) == FW_kNonSystem75WindoidWDEF)
  597.         {
  598.             if (FW_gMacFloatWindowProc == NULL)
  599.             {
  600.                 FW_gMacFloatWindowProc = ((WindowPeek)platformWindow)->windowDefProc;
  601.                 ::DetachResource(FW_gMacFloatWindowProc);
  602.             }
  603.             else
  604.             {
  605.                 Handle temp = ((WindowPeek)platformWindow)->windowDefProc;
  606.                 ((WindowPeek)platformWindow)->windowDefProc = FW_gMacFloatWindowProc;
  607.                 ::ReleaseResource(temp);
  608.             }
  609.         }
  610.     }
  611.     FW_SOM_CATCH
  612.     
  613.     return platformWindow;
  614. }
  615. #endif
  616.  
  617. #ifdef FW_BUILD_MAC
  618. //----------------------------------------------------------------------------------------
  619. //    FW_PrivMacTrackResizeWindow
  620. //----------------------------------------------------------------------------------------
  621.  
  622. FW_Boolean FW_PrivMacTrackResizeWindow(ODPlatformWindow platformWindow, 
  623.                                         const FW_SRect& growLimits, 
  624.                                         FW_SPlatformPoint startPoint,
  625.                                         FW_PlatformError* error)
  626. {
  627.     FW_CPoint currentSize;
  628.     ::FW_GetWindowSize(platformWindow, currentSize, error);
  629.     if (*error)
  630.         return false;
  631.     
  632.      FW_CPlatformRect plfmGrowLimits(growLimits);
  633.     long newWindowSize = ::GrowWindow(platformWindow, startPoint, &plfmGrowLimits);
  634.     
  635.     if (newWindowSize != 0)
  636.     {
  637.         FW_CPoint interiorSize(FW_IntToFixed(LoWord(newWindowSize)), FW_IntToFixed(HiWord(newWindowSize)));    
  638.         FW_SetWindowSize(platformWindow, interiorSize, error);
  639.         return *error == FW_xNoError;
  640.     }
  641.     else
  642.         return FALSE;
  643. }
  644. #endif
  645.  
  646. #ifdef FW_BUILD_MAC
  647. //----------------------------------------------------------------------------------------
  648. //    FW_PrivMacDoZoom
  649. //----------------------------------------------------------------------------------------
  650.  
  651. void FW_PrivMacDoZoom(ODPlatformWindow platformWindow,
  652.                         const FW_SPoint& zoomedSize, 
  653.                         const FW_SRect& borderSize,
  654.                         const FW_SRect& screenRect,
  655.                         unsigned long message,
  656.                         FW_PlatformError* error)
  657. {
  658.     // No try block necessary - Do not throw
  659.     *error = FW_xNoError;
  660.  
  661.     if (message == inZoomOut)
  662.     {
  663.         // ----- Calculate the outside bounds of the window -----
  664.         FW_CPoint windowPos;
  665.         FW_GetWindowPosition(platformWindow, windowPos, error);
  666.         if (*error)
  667.             return;
  668.         
  669.         FW_CRect windowRect(windowPos.x, 
  670.                             windowPos.y,
  671.                             windowPos.x + zoomedSize.x + borderSize.left + borderSize.right,
  672.                             windowPos.y + zoomedSize.y + borderSize.top + borderSize.bottom);
  673.         
  674.         // ----- Be sure that it fits on the screen -----
  675.         FW_PrivFitRect(screenRect, windowRect);
  676.         
  677.         // ----- Calculate the inside -----
  678.         windowRect.left += borderSize.left;
  679.         windowRect.right -= borderSize.right;
  680.         windowRect.top += borderSize.top;
  681.         windowRect.bottom -= borderSize.bottom;
  682.         
  683.         // ----- and set the stdState -----
  684.         (*((WStateDataHandle)(((WindowPeek)platformWindow)->dataHandle)))->stdState = windowRect.AsPlatformRect();
  685.     }
  686.  
  687.     *error =::FW_MacZoomWindow(platformWindow, message == inZoomIn);
  688. }
  689. #endif
  690.  
  691. #ifdef FW_BUILD_MAC
  692. //----------------------------------------------------------------------------------------
  693. //    FW_PrivMacStyleToProcId
  694. //----------------------------------------------------------------------------------------
  695.  
  696. unsigned short FW_PrivMacStyleToProcId(FW_WindowStyle windowStyle)
  697. {
  698.     // No try block necessary - Do not throw
  699.     unsigned short procId;
  700.     
  701.     if (windowStyle & FW_kStandardWindow)
  702.     {
  703.         if (windowStyle & FW_kResizeable)
  704.             if (windowStyle & FW_kHasMaximizeBox)
  705.                 procId = zoomDocProc;
  706.             else
  707.                 procId = documentProc;
  708.         else if (windowStyle & FW_kHasMaximizeBox)
  709.             procId = zoomNoGrow;
  710.         else
  711.             procId = noGrowDocProc;
  712.     }
  713.     else if (windowStyle & FW_kModelessDialog)
  714.     {
  715.         procId = documentProc;
  716.     }
  717.     else if (windowStyle & FW_kModalDialog)
  718.     {
  719.         if (windowStyle & FW_kHasCaption)
  720.             procId = movableDBoxProc;
  721.         else
  722.             procId = dBoxProc;
  723.  
  724.     }
  725.     else if (windowStyle & FW_kFloatingWindow)
  726.     {
  727.         // Check first if we have the system 7.5 resource
  728.         Handle hld = ::GetResource('WDEF', 124);
  729.         if (hld == NULL)
  730.             procId = FW_kNonSystem75WindoidWDEF;
  731.         else
  732.             procId = FW_kSystem75WindoidWDEF;
  733.  
  734.         if (windowStyle & FW_kHasMaximizeBox)
  735.             procId += FW_kSystem75HasZoom;
  736.         if (windowStyle & FW_kResizeable)
  737.             procId += FW_kSystem75HasGrow;
  738.     }
  739. //    else if (windowStyle & FW_kMacDesktopPane)
  740. //    {
  741. //        procId = plainDBox;
  742. //    }
  743.     else
  744.     {
  745.         FW_ASSERT(FALSE);
  746.         procId = documentProc;
  747.     }
  748.     
  749.     return procId;
  750. }
  751. #endif
  752.  
  753. #ifdef FW_BUILD_WIN
  754. //----------------------------------------------------------------------------------------
  755. //    FW_PrivWindStyleToWindowsFlags
  756. //----------------------------------------------------------------------------------------
  757.  
  758. DWORD SL_API FW_PrivWindStyleToWindowsFlags(FW_WindowStyle style, FW_PlatformError* error)
  759. {
  760.     // No try block necessary - Do not throw
  761.     *error = FW_xNoError;
  762.  
  763.     DWORD dwStyle = 0;
  764.  
  765.     if (style & FW_kStandardWindow)
  766.         dwStyle |= WS_CHILD;
  767.     else if (style & FW_kOverlappedWindow)
  768.         dwStyle |= WS_OVERLAPPED;
  769.     else if (style & FW_kFloatingWindow)
  770.         dwStyle |= /*WS_POPUP |*/ WS_CAPTION;
  771.     else if (style & FW_kModelessDialog)
  772.         dwStyle |= (WS_POPUP | DS_MODALFRAME);
  773.     else if (style & FW_kModalDialog)
  774.         dwStyle |= (WS_POPUP | DS_MODALFRAME);// DS_MODALFRAME will be transform into WS_EX_DLGMODALFRAME
  775.     else
  776.         FW_ASSERT(FALSE);
  777.         
  778.     if (style & FW_kResizeable)
  779.         dwStyle |= WS_THICKFRAME;
  780.  
  781.     if (style & FW_kHasCaption)
  782.         dwStyle |= WS_CAPTION;
  783.  
  784.     if (style & FW_kHasCloseBox)
  785.         dwStyle |= WS_SYSMENU;
  786.  
  787.     if (style & FW_kHasMinimizeBox)
  788.         dwStyle |= WS_MINIMIZEBOX;
  789.  
  790.     if (style & FW_kHasMaximizeBox)
  791.         dwStyle |= WS_MAXIMIZEBOX;
  792.  
  793.     return dwStyle;
  794. }
  795. #endif
  796.  
  797. #ifdef FW_BUILD_WIN
  798. //----------------------------------------------------------------------------------------
  799. // FW_PrivWindFixSystemMenu
  800. //----------------------------------------------------------------------------------------
  801. //    Makes system menu consistent with platform dialogs
  802.  
  803. void SL_API FW_PrivWindFixSystemMenu(FW_WindowStyle windowStyle, FW_PlatformError* error)
  804. {
  805. #if 0
  806.     // No try block necessary - Do not throw
  807.     *error = FW_xNoError;
  808.  
  809.     // Make system menu standard for windows dialogs
  810.     HMENU fMenuHandle = ::GetSystemMenu(GetPlatformWindow(), FALSE);
  811.  
  812.     if (fMenuHandle != NULL)
  813.     {
  814.         BR_CBedrock* bedrock = BR_CBedrock::GetBedrock();
  815.         BR_CCharString255 MenuText;
  816.         
  817.         // Delete all items
  818.         while (::DeleteMenu(fMenuHandle, 0, MF_BYPOSITION))
  819.             ;
  820.  
  821.         // Flags for ::AppendMenu()
  822.         const WORD wfItemFlags = MF_BYCOMMAND | MF_ENABLED | MF_STRING;
  823.  
  824.         // Add in dialog menu
  825.         if (windowStyle & (kHasMinimizeBox | FW_kHasMaximizeBox))
  826.         {
  827.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_RESTORE, MenuText);
  828.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_RESTORE, MenuText);
  829.         }
  830.  
  831.  
  832.         {
  833.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MOVE, MenuText);
  834.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_MOVE, MenuText);
  835.         }
  836.  
  837.         if (windowStyle & FW_kResizeable)
  838.         {
  839.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_SIZE, MenuText);
  840.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_SIZE, MenuText);
  841.         }
  842.  
  843.         if (windowStyle & FW_kHasMinimizeBox)
  844.         {
  845.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MINIMIZE, MenuText);
  846.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_MINIMIZE, MenuText);
  847.         }
  848.  
  849.         if (windowStyle & FW_kHasMaximizeBox)
  850.         {
  851.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MAXIMIZE, MenuText);
  852.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_MAXIMIZE, MenuText);
  853.         }
  854.  
  855.         ::AppendMenu(fMenuHandle, MF_SEPARATOR, 0, NULL);
  856.  
  857.         {
  858.             bedrock->LoadString(IDSL_SYSTEMMENU, IDS_CLOSE, MenuText);
  859.             ::AppendMenu(fMenuHandle, wfItemFlags, SC_CLOSE, MenuText);
  860.         }
  861.     }
  862. #endif
  863. }
  864. #endif
  865.  
  866.